package fire.and.near.challenger;

import java.util.List;

import fire.and.near.challenger.database.FriendModel;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class FriendPickerListAdapter extends ArrayAdapter<FriendModel> {

	private Context context;
	private FriendPickerListAdapter mThisAdapter;

	public FriendPickerListAdapter(Context context, int resource) {
		super(context, resource);
		
		this.context = context;
		this.mThisAdapter = this;
	}

	public FriendPickerListAdapter(Context context, int resource,
			List<FriendModel> objects) {
		super(context, resource, objects);
		
		this.context = context;
		this.mThisAdapter = this;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		if (v == null) {
			LayoutInflater inflater = ((Activity) this.getContext())
					.getLayoutInflater();
			v = inflater.inflate(R.layout.friend_picker_list_row, null);
		}
		
		FriendModel fr = getItem(position);
		
		if (fr != null) {
			((TextView) v.findViewById(R.id.textView_friend_name)).setText(fr.getName());
		}
		
		return v;
	}
}
